home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 September / macformat-028.iso / mac / Shareware City / Developers / BoxMaker++ / NameLocker ƒ / NameFileLocker.cp < prev    next >
Encoding:
Text File  |  1995-06-14  |  1.7 KB  |  94 lines  |  [TEXT/KAHL]

  1. #include <Types.h>
  2. #include <Memory.h>
  3. #include <QuickDraw.h>
  4. #include <OSUtils.h>
  5. #include <ToolUtils.h>
  6. #include <Menus.h>
  7. #include <Packages.h>
  8. #include <Traps.h>
  9. #include <Files.h>
  10. #include <Aliases.h>
  11. #include <AppleEvents.h>
  12. #include <GestaltEqu.h>
  13. #include <Processes.h>
  14. #include <Fonts.h>
  15. #include <OSEvents.h>
  16. #include <Resources.h>
  17. #include <Desk.h>
  18. #include <Finder.h>
  19.  
  20. #include "standardgetfile.h"
  21. #include "boxmakergetfile.h"
  22.  
  23. #include "boxmaker constants.h"
  24. #include "boxmaker.h"
  25. #include "preferences.cp"
  26. #include "NameFileLocker.h"
  27.  
  28. #pragma template_access public
  29.  
  30. void main();
  31.  
  32. void main()
  33. {
  34.     Handle theSettings = Get1Resource( 'what', 128);
  35.     if( theSettings != 0)
  36.     {
  37.         HLock( theSettings);
  38.         char *set = *theSettings;
  39.         
  40.         const int FileLockAction = set[ 0];
  41.         const int NameLockAction = set[ 1];
  42.         
  43.         ReleaseResource( theSettings);
  44.         NameFileLocker it( FileLockAction, NameLockAction);
  45.         it.run();
  46.     } else {
  47.         DebugStr( "\pCould not get 'what' resource");
  48.     }
  49. }
  50.  
  51. NameFileLocker::NameFileLocker( int theFileAction, int theNameAction)
  52.     : boxmaker( 3000)
  53.     , fileAction( theFileAction)
  54.     , nameAction( theNameAction)
  55. {    
  56. }
  57.  
  58. void NameFileLocker::OpenDoc( Boolean opening)
  59. {
  60.     if( opening)
  61.     {
  62.         FInfo theInfo;
  63.         
  64.         switch( fileAction)
  65.         {
  66.             case kLockFile:
  67.                 (void)FSpSetFLock( &theFSSpec);
  68.                 break;
  69.             
  70.             case kUnlockFile:
  71.                 (void)FSpRstFLock( &theFSSpec);
  72.                 break;
  73.  
  74.             case kIgnoreFile:
  75.                 ;
  76.         }
  77.         if( nameAction != kIgnoreName)
  78.         {
  79.             if( FSpGetFInfo( &theFSSpec, &theInfo) == noErr)
  80.             {
  81.                 theInfo.fdFlags &= ~kHasBeenInited;
  82.                 
  83.                 if( nameAction == kLockName)
  84.                 {
  85.                     theInfo.fdFlags |= kNameLocked;
  86.                 } else {
  87.                     theInfo.fdFlags &= ~kNameLocked;
  88.                 }
  89.                 (void)FSpSetFInfo( &theFSSpec, &theInfo);
  90.             }
  91.         }
  92.     }
  93. }
  94.